<template>
    <div>
        <h1>房号信息显示</h1>
        <hr>
        <a href="/NAdd">房号信息新增</a>
        <hr>
        房间类型:
                        <select v-model="cha.TId">
                            <option value="0">请选择</option>
                            <option v-for="a in bang" :value="a.TId">{{a.Name}}</option>
                        </select>

        门店名称：
                        <select v-model="cha.HId">
                            <option value="0">请选择</option>
                            <option v-for="a in bang1" :value="a.HId">{{a.HName}}</option>
                        </select>
                        <input type="button" value="查询" @click="NShow()">

        <table class="table">
            <thead>
                <tr>
                    <td>房号编号</td>
                    <td>房间号</td>
                    <td>房间名称</td>
                    <td>房间类型</td>
                    <td>门店名称</td>
                    <td>房间状态</td>
                    <td>操作</td>
                </tr>
            </thead>
            <tbody>
                <tr v-for="a in data">
                    <td>{{a.RId}}</td>
                    <td>{{a.RNum}}</td>
                    <td>{{a.RName}}</td>
                    <td>{{a.Name}}</td>
                    <td>{{a.HName}}</td>
                    <td>{{a.RState?"上架":"下架"}}</td>
                    <td>
                        <input type="button" value="删除" @click="Del(a.RId)">
                        <input type="button" value="修改状态" @click="UpdState(a.RId)">
                        <input type="button" value="详情" @click="Upd(a.RId)">
                    </td>
                </tr>
            </tbody>
        </table>



    </div>
</template>

<script setup lang="ts">

import { ref,onMounted } from 'vue';
import axios from 'axios';
import { useRouter } from 'vue-router';

onMounted(()=>{
    NShow()
    xia()
    xia1()
})



const bang = ref([{
    "TId": 1,
    "Name": "毛坯房"
}])
const xia = ()=>{
    axios.get('https://localhost:7206/api/RoomNum/Xia1').then(res=>{
        bang.value = res.data
    })
}
const bang1 = ref([{
    "HId": 1,
    "HName": "轻轻饭店",
    "HProName": "青青",
    "HImg": "/img/2a097dd3-6727-4649-ba95-4a1aa915722e2.png",
    "MDate": "2025-06-16T07:57:40.365",
    "HApp": "山西临汾",
    "HState": false
}])
const xia1 = ()=>{
    axios.get('https://localhost:7206/api/RoomNum/Xia2').then(res=>{
        bang1.value = res.data
    })
}
const data = ref([{
    "RId": 1,
    "RNum": "101",
    "RName": "财务房",
    "RState": true,
    "IsDelete": true,
    "TId": 2,
    "Name": "精装修",
    "HId": 2,
    "HName": "香香花店"
}])
const cha = ref({
    TId:0,
    HId:0
})
const NShow=()=>{
    axios.get('https://localhost:7206/api/RoomNum/NShow',{params:cha.value}).then(res=>{
        data.value = res.data;
    })
}

//删除
const Del = (e:any)=>{
    if(confirm("确定删除？")){
        axios.get('https://localhost:7206/api/RoomNum/NDel',{params:{RId:e}}).then(res=>{
            if(res.data>0){
                alert('删除成功')
                NShow()
            }
            else{
                alert('删除失败')
            }
        })
    }
}

//修改状态
const UpdState = (e:any)=>{
    if(confirm("确定修改？")){
        axios.get('https://localhost:7206/api/RoomNum/NUpdState',{params:{RId:e}}).then(res=>{
            if(res.data>0){
                alert('修改成功')
                NShow()
            }
            else{
                alert('修改失败')
            }
        })
    }
}
const router = useRouter()
//详情
const Upd=(e:any)=>{
    if(confirm("确定查看详情？")){
        router.push({path:"/NUpd",query:{RId:e}});
    }
    
}


</script>

<style scoped>

</style>